package com.sz.framework.trace;

import com.sz.framework.component.SzAggregator;
import com.sz.framework.utils.CommonUtil;

import java.util.Collection;
import java.util.List;

/**
 * traceId探测器的聚合器
 *
 * @author: yxl
 * 2025-07-24
 */
public class SzTraceIdDetectorAggregator implements SzAggregator<String, SzTraceIdDetector> {

    private List<SzTraceIdDetector> detectors;

    public SzTraceIdDetectorAggregator(List<SzTraceIdDetector> detectors) {
        this.detectors = detectors;
    }

    @Override
    public String get() {
        String traceId = null;
        for(SzTraceIdDetector detector : detectors){
            traceId = detector.get();
            if(!CommonUtil.isEmpty(traceId)){
                break;
            }
        }
        return traceId;
    }

    @Override
    public Collection<SzTraceIdDetector> getDetectors() {
        return detectors;
    }
}
